<template>
  <div class="head-nav">
    <el-row>
      <el-col :span="6" class="nav-left">
          <img src="./../assets/logo.jpg" alt="" class="logo">
          <span class="title">
            无痕在线后台资金管理系统
          </span>
      </el-col>
      <el-col :span="6" class="nav-right">
          <img :src="avatar" alt="" class="avatar">
          <div class="text">
            <p>欢迎</p>
            <span>{{user.name}}</span>
          </div>
          <div class="moreInfo">
            <el-dropdown trigger="click" @command="setDialogInfo">
              <span class="el-dropdown-link">
                <i class="el-icon-caret-bottom el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="info">个人信息</el-dropdown-item>
                <el-dropdown-item command="logout">退出</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  export default {
    name: "HeadNav",
    computed: {
      user(){
        return this.$store.getters.user;
      },
      avatar(){
        return this.$store.getters.avatar;
      }
    },
    methods: {
      setDialogInfo(cmdItem){
        // console.log(cmdItem);
        switch (cmdItem) {
          case "info":
            this.showInfoList();
            break;
          case "logout":
            this.logout();
            break;
        }
      },
      showInfoList(){
        this.$router.push('/infoshow');
      },
      logout(){
        //清除token
        localStorage.removeItem('wuhenToken');
        //清除头像
        localStorage.removeItem('wuhenToken');
        //设置vuex里的store
        this.$store.dispatch('clearCurrentStore');
        
        //跳转到登录页面
        this.$router.push('/login');
      }
    }
  };
</script>

<style scoped>
  .head-nav{
    width: 100%;
    min-width: 600px;
    height: 60px;
    color: white;
    font-weight: bold;
    background-color: #324057;
    border-bottom: 1px solid #1f2d3d;
  }
  .nav-left{
    min-width: 400px;
    height: 60px;
    display: flex;
    align-items: center;
  }
  .logo{
    width: 50px;
    height: 50px;
    margin-left: 10px;
    margin-right: 6px;
    display: inline-block;
    vertical-align: center;
    border-radius: 50%;
  }
  .title{
    font-family: "Microsoft YaHei";
    line-height: 60px;
  }
  .nav-right{
    float: right;
    height: 60px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
  }
  .nav-right>*{
    margin-right: 10px;
  }
  .avatar{
    width: 50px;
    height: 50px;
    border-radius: 50%;
  }
  .text{
    height: 50px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-end;
    cursor: default;
  }
  .text>p{
    font-size: 12px;
    margin-bottom: 5px;
  }
  .text>span{
    color: #409eff;
    font-size: 14px;
    font-weight: bolder;
    margin-top: 5px;

  }
  .el-dropdown{
    /*可定义一些el-dropdown标签的样式*/
    color: #ffffff;
  }
</style>